//
//  MZOtherDemoViewController.m
//  MZToolDemo
//
//  Created by Chris Yang on 2016/12/12.
//  Copyright © 2016年 Chris Yang. All rights reserved.
//

#import <YYCategories.h>

#import "MZTool.h"
#import "UIColor+MZBase.h"
#import "UIView+MZLayout.h"
#import "UIButton+MZBase.h"
#import "MZDemoSupprot.h"
#import "MZCompatible.h"
#import "NSDate+MZBase.h"
#import "MZCommonInfo.h"
#import "NSString+MZCategory.h"

#import "MZOtherDemoViewController.h"

@interface MZOtherDemoViewController ()

@property (nonatomic, strong) NSArray *testButtonArray;

@end

@implementation MZOtherDemoViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self resetTestButtonWithNumber:8];
    
    NSArray *titleArray = @[
                            @"基本宏测试[完整性]",
                            @"字典取值[完整性]",
                            @"数组字典常用[完整性]",
                            @"日期转换",
                            @"信息获取",
                            @"基础字符串",
                            @"其他",
                            @"信息获取(位置)",
                            ];
    [self setButtonTitle:titleArray];
}

#pragma mark -

- (void)resetTestButtonWithNumber:(NSInteger)number {
    
    for (UIButton *tmpButton in _testButtonArray) {
        [tmpButton removeFromSuperview];
    }
    
    CGRect tmpRect = [self.view mzCenterRectInSubviewWithWidth:160 height:50 toTop:80];
    
    NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
    for (int i = 0; i < number; i++) {
        
        UIButton *tmpButton = [MZDemoSupprot mzDemoButton];
        
        tmpButton.tag = i;
        [tmpButton setTitle:[NSString stringWithFormat:@"%d", i] forState:UIControlStateNormal];
        [tmpButton setBackgroundColor:MZRandColor(0.5)];
        [tmpButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [tmpButton mzEnlargeTop:0 right:100 bottom:0 left:100];
        [self.view addSubview:tmpButton];
        
        [tmpButton setFrame:tmpRect];
        tmpRect.origin.y += 70;
        
        [tmpArray addObject:tmpButton];
    }
    _testButtonArray = [NSArray arrayWithArray:tmpArray];
}

#pragma mark -

#define __quickCall(index) \
if (index == button.tag) { \
[self test##index]; \
} \

- (void)buttonClicked:(UIButton *)button {
    __quickCall(0);
    __quickCall(1);
    __quickCall(2);
    __quickCall(3);
    __quickCall(4);
    __quickCall(5);
    __quickCall(6);
    __quickCall(7);
}

- (void)setButtonTitle:(NSArray *)titleArray {
    
    for (int i = 0 ; i < MIN(titleArray.count, _testButtonArray.count); i++) {
        UIButton *tmpButton = _testButtonArray[i];
        [tmpButton setTitle:titleArray[i] forState:UIControlStateNormal];
    }
}

#pragma mark -

- (void)test0 {
    
    NSString *nilId = nil;
    NSArray *nilArray = nil;
    NSDictionary *nilDic = nil;
    
    NSLog(@"基本宏测试");
    
    NSLog(@"mzSafeStr %@", mzSafeStr(nilId));
    NSLog(@"mzSafeStr %@", mzSafeStr(@(1)));
    NSLog(@"mzSafeStr %@", mzSafeStr(@"111"));
    
    NSLog(@"mzSafeArray %@", mzSafeArray(nilId));
    NSLog(@"mzSafeArray %@", mzSafeArray(@"xxxx"));
    NSLog(@"mzSafeArray %@", mzSafeArray(@[@"aaa"]));
    
    NSLog(@"mzSafeDic %@", mzSafeDic(nilId));
    NSLog(@"mzSafeDic %@", mzSafeDic(@"xxxx"));
    NSLog(@"mzSafeDic %@", mzSafeDic(@{@"aaa":@"bbb"}));
    
    NSLog(@"mzSafeDecimal %@", mzSafeDecimal(nilId));
    NSLog(@"mzSafeDecimal %@", mzSafeDecimal(@"xxxx"));
    NSLog(@"mzSafeDecimal %@", mzSafeDecimal([NSDecimalNumber decimalNumberWithString:@"3.77"]));
    
    NSLog(@"mzIsEmptyStr %d", mzIsEmptyStr(nilId));
    NSLog(@"mzIsEmptyStr %d", mzIsEmptyStr(@""));
    NSLog(@"mzIsEmptyStr %d", mzIsEmptyStr(@"xxxx"));
    
    NSLog(@"mzIsEmptyArray %d", mzIsEmptyArray(nilArray));
    NSLog(@"mzIsEmptyArray %d", mzIsEmptyArray(@[]));
    NSLog(@"mzIsEmptyArray %d", mzIsEmptyArray(@[@"aaa"]));
    
    NSLog(@"mzIsEmptyDic %d", mzIsEmptyDic(nilDic));
    NSLog(@"mzIsEmptyDic %d", mzIsEmptyDic(@{}));
    NSLog(@"mzIsEmptyDic %d", mzIsEmptyDic(@{@"aaa":@"bbb"}));
    
    NSLog(@"mzIsZeroDecimal %d", mzIsZeroDecimal(nilId));
    NSLog(@"mzIsZeroDecimal %d", mzIsZeroDecimal([NSDecimalNumber decimalNumberWithString:@"0"]));
    NSLog(@"mzIsZeroDecimal %d", mzIsZeroDecimal([NSDecimalNumber decimalNumberWithString:@"3.77"]));
}

- (void)test1 {
    
    NSLog(@"NSDictionary+Safe Test");
    
    [NSDictionary setEnableDefaultVal:YES];
    [self _test1];
    [NSDictionary setEnableDefaultVal:NO];
    [self _test1];
}

- (void)_test1 {
    
    NSDictionary *tmpDic = @{
                             @"num":@(111),
                             @"strNum":@"222",
                             @"str":@"hahaha",
                             @"array":@[@"xixixi"],
                             @"dic":@{@"aaa":@"bbb"},
                             };
    
    NSLog(@"mzNumberObjectForKey %@", [tmpDic mzNumberObjectForKey:@"num"]);
    NSLog(@"mzNumberObjectForKey %@", [tmpDic mzNumberObjectForKey:@"strNum"]);
    NSLog(@"mzNumberObjectForKey %@", [tmpDic mzNumberObjectForKey:@"str"]);
    NSLog(@"mzNumberObjectForKey %@", [tmpDic mzNumberObjectForKey:@"array"]);
    NSLog(@"mzNumberObjectForKey %@", [tmpDic mzNumberObjectForKey:@"dic"]);
    NSLog(@"mzNumberObjectForKey %@", [tmpDic mzNumberObjectForKey:@"xxxx"]);
    
    NSLog(@"mzDecimalNumberObjectForKey %@", [tmpDic mzDecimalNumberObjectForKey:@"num"]);
    NSLog(@"mzDecimalNumberObjectForKey %@", [tmpDic mzDecimalNumberObjectForKey:@"strNum"]);
    NSLog(@"mzDecimalNumberObjectForKey %@", [tmpDic mzDecimalNumberObjectForKey:@"str"]);
    NSLog(@"mzDecimalNumberObjectForKey %@", [tmpDic mzDecimalNumberObjectForKey:@"array"]);
    NSLog(@"mzDecimalNumberObjectForKey %@", [tmpDic mzDecimalNumberObjectForKey:@"dic"]);
    NSLog(@"mzDecimalNumberObjectForKey %@", [tmpDic mzDecimalNumberObjectForKey:@"xxxx"]);
    
    NSLog(@"mzStringObjectForKey %@", [tmpDic mzStringObjectForKey:@"num"]);
    NSLog(@"mzStringObjectForKey %@", [tmpDic mzStringObjectForKey:@"strNum"]);
    NSLog(@"mzStringObjectForKey %@", [tmpDic mzStringObjectForKey:@"str"]);
    NSLog(@"mzStringObjectForKey %@", [tmpDic mzStringObjectForKey:@"array"]);
    NSLog(@"mzStringObjectForKey %@", [tmpDic mzStringObjectForKey:@"dic"]);
    NSLog(@"mzStringObjectForKey %@", [tmpDic mzStringObjectForKey:@"xxxx"]);
    
    NSLog(@"mzArrayObjectForKey %@", [tmpDic mzArrayObjectForKey:@"num"]);
    NSLog(@"mzArrayObjectForKey %@", [tmpDic mzArrayObjectForKey:@"strNum"]);
    NSLog(@"mzArrayObjectForKey %@", [tmpDic mzArrayObjectForKey:@"str"]);
    NSLog(@"mzArrayObjectForKey %@", [tmpDic mzArrayObjectForKey:@"array"]);
    NSLog(@"mzArrayObjectForKey %@", [tmpDic mzArrayObjectForKey:@"dic"]);
    NSLog(@"mzArrayObjectForKey %@", [tmpDic mzArrayObjectForKey:@"xxxx"]);
    
    NSLog(@"mzDictionaryObjectForKey %@", [tmpDic mzDictionaryObjectForKey:@"num"]);
    NSLog(@"mzDictionaryObjectForKey %@", [tmpDic mzDictionaryObjectForKey:@"strNum"]);
    NSLog(@"mzDictionaryObjectForKey %@", [tmpDic mzDictionaryObjectForKey:@"str"]);
    NSLog(@"mzDictionaryObjectForKey %@", [tmpDic mzDictionaryObjectForKey:@"array"]);
    NSLog(@"mzDictionaryObjectForKey %@", [tmpDic mzDictionaryObjectForKey:@"dic"]);
    NSLog(@"mzDictionaryObjectForKey %@", [tmpDic mzDictionaryObjectForKey:@"xxxx"]);
}

- (void)test2 {
    
    NSString *nilStr = nil;
    NSArray *tmpArray = @[@"111", @"222"];
    
    NSLog(@"mzContainsString %d", [@"1234567" containsString:@"234"]);
    NSLog(@"mzContainsString %d", [@"1234567" containsString:@"567"]);
    NSLog(@"mzContainsString %d", [@"1234567" containsString:@"145"]);
    NSLog(@"mzContainsString %d", [@"1234567" containsString:@"009"]);
    
    NSLog(@"mzObjectAtIndex %@", [tmpArray mzObjectAtIndex:0]);
    NSLog(@"mzObjectAtIndex %@", [tmpArray mzObjectAtIndex:1]);
    NSLog(@"mzObjectAtIndex %@", [tmpArray mzObjectAtIndex:2]);
    
    NSMutableArray *tmpMulArray = [[NSMutableArray alloc] init];
    [tmpMulArray mzAddObject:nilStr];
    NSLog(@"Array %@", tmpMulArray);
    
    NSMutableDictionary *tmpMulDic = [[NSMutableDictionary alloc] init];
    [tmpMulDic mzSetObject:nilStr forKey:@"xxx"];
    [tmpMulDic mzSetObject:@"xxx" forKey:nilStr];
    [tmpMulDic mzSetObject:nilStr forKey:nilStr];
    NSLog(@"Dic %@", tmpMulDic);
}

- (void)test3 {
    
    /* Date Transfer 测试 */
    NSDate *tmpDate = nil;
    NSString *tmpStr = nil;
    
    tmpStr = [[NSDate date] mzDateString];
    tmpDate = [NSDate mzDateFromDateStr:tmpStr];
    NSLog(@"STR %@", tmpStr);
    NSLog(@"DATE %@", tmpDate);
    NSLog(@"%@", [tmpDate mzDateString]);
    NSLog(@"");
    
    tmpStr = [[NSDate date] mzTimeString];
    tmpDate = [NSDate mzDateFromDateStr:tmpStr];
    NSLog(@"STR %@", tmpStr);
    NSLog(@"DATE %@", tmpDate);
    tmpStr = [tmpDate mzTimeString];
    tmpDate = [NSDate mzDateFromDateStr:tmpStr];
    NSLog(@"STR %@", tmpStr);
    NSLog(@"DATE %@", tmpDate);
    NSLog(@"%@", [tmpDate mzTimeString]);
    NSLog(@"");
    
    tmpStr = [[NSDate date] mzDateTimeString];
    tmpDate = [NSDate mzDateFromDateStr:tmpStr];
    NSLog(@"STR %@", tmpStr);
    NSLog(@"DATE %@", tmpDate);
    NSLog(@"");
    
    tmpStr = [NSString stringWithFormat:@"%lld", (long long)[[NSDate date] timeIntervalSince1970]];
    tmpDate = [NSDate mzDateFromDateStr:tmpStr];
    NSLog(@"STR %@", tmpStr);
    NSLog(@"DATE %@", tmpDate);
    NSLog(@"%@", [NSString stringWithFormat:@"%lld", (long long)[tmpDate timeIntervalSince1970]]);
    NSLog(@"");
}

- (void)test4 {
    
    /* Info Getter 测试 */
    NSLog(@"mzOSVersionString %@", [UIDevice mzOSVersionString]);
    NSLog(@"mzPhoneTypeString %@", [UIDevice mzPhoneTypeString]);
    NSLog(@"mzDeviceTokenString %@", [UIDevice mzDeviceTokenString]);
    NSLog(@"mzIspInfoString %@", [UIDevice mzIspInfoString]);
    NSLog(@"mzNetTypeString %@", [UIDevice mzNetTypeString]);
    NSLog(@"mzInnerIpString %@", [UIDevice mzInnerIpString]);
    NSLog(@"mzGuidString %@", [UIDevice mzGuidString]);
}

- (void)test5 {
    
    NSLog(@"mzNoSpaceString %@", [@"laj  ojoencas d3" mzNoSpaceString]);
    NSLog(@"");
    
    NSLog(@"mzRegexStrPassword %d", [@"12d3234" mzMatchRegexStr:mzRegexStrPassword]);
    NSLog(@"mzRegexStrPassword %d", [@"1$#2d3234" mzMatchRegexStr:mzRegexStrPassword]);
    NSLog(@"mzRegexStrPassword %d", [@"kldajoeeo3u987971921hfh3948" mzMatchRegexStr:mzRegexStrPassword]);
    NSLog(@"");
    
    NSLog(@"mzRangeStrIdentify %d", [@"410703199101272035" mzMatchRegexStr:mzRangeStrIdentify]);
    NSLog(@"mzRangeStrIdentify %d", [@"4107031991012ef035" mzMatchRegexStr:mzRangeStrIdentify]);
    NSLog(@"");
    
    NSLog(@"mzRegexStrMobildNum %d", [@"13145000627" mzMatchRegexStr:mzRegexStrMobildNum]);
    NSLog(@"mzRegexStrMobildNum %d", [@"2333d312343" mzMatchRegexStr:mzRegexStrMobildNum]);
    NSLog(@"mzRegexStrMobildNum %d", [@"1314500062d" mzMatchRegexStr:mzRegexStrMobildNum]);
    NSLog(@"mzRegexStrMobildNum %d", [@"1234254332" mzMatchRegexStr:mzRegexStrMobildNum]);
    NSLog(@"mzRegexStrMobildNum %d", [@"123425433223" mzMatchRegexStr:mzRegexStrMobildNum]);
    NSLog(@"");
    
    NSLog(@"mzRegexStrBankCard %d", [@"6214855120215526" mzMatchRegexStr:mzRegexStrBankCard]);
    NSLog(@"mzRegexStrBankCard %d", [@"621485512021552" mzMatchRegexStr:mzRegexStrBankCard]);
    NSLog(@"mzRegexStrBankCard %d", [@"62148551202155213429" mzMatchRegexStr:mzRegexStrBankCard]);
    NSLog(@"");
    

    
    NSLog(@"mzRegexStrAmount %d",[@"12345678.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"02345678.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"123456789.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"12345678.011" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"1234567.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"123456.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"12345.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"1234.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"123.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"12.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"1.0" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@"0.01" mzMatchRegexStr:mzRegexStrAmount]);
    NSLog(@"mzRegexStrAmount %d",[@".01" mzMatchRegexStr:mzRegexStrAmount]);
}

- (void)test6 {
    
    NSLog(@"");
    
    NSDictionary *tmpDic = @{
                             @"111":@(111),
                             @"222":@(222),
                             @"333":@(333),
                             @"444":@(444),
                             };
    
    NSArray *tmpArray = @[@"a", @"b", @"c"];
    
    NSString *tmpStr = [MZTool mzJsonStingFromObject:tmpDic];
    NSLog(@"mzJsonStingFromObject %@", tmpStr);
    NSLog(@"mzJsonObjectFromString %@", [MZTool mzJsonObjectFromString:tmpStr]);
    
    tmpStr = [MZTool mzJsonStingFromObject:tmpArray];
    NSLog(@"mzJsonStingFromObject %@", tmpStr);
    NSLog(@"mzJsonObjectFromString %@", [MZTool mzJsonObjectFromString:tmpStr]);
}

- (void)test7 {
    [CLLocation mzLocationUpdate];
    [self performSelector:@selector(_test7) withObject:nil afterDelay:2];
}

- (void)_test7 {
    
    CLLocation *tmpLocation = [CLLocation mzLocation];
    NSLog(@"Longitude %.2lf", [CLLocation mzLongitudeStringWithLocationInfo:tmpLocation]);
    NSLog(@"Latitude %.2lf", [CLLocation mzLatitudeStringWithLocationInfo:tmpLocation]);
}

@end
